package MyApp.View.well
{
	import MyApp.Model.WellPrdRecord;
	import MyApp.Model.proxy.WellProxy;
	import MyApp.MyAppFacade;
	
	import components.well.AddPrdRecord;
	import components.well.ProductionRecord;
	import components.well.UpdatePrdRecord;
	import components.well.WellContext;
	import components.well.WellWindow;
	
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import util.Event.ValueEvent;
	
	public class ProductionRecordMediator extends Mediator
	{
		public static const NAME:String="ProductionRecordMediator";
		public function ProductionRecordMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			view.addEventListener(ProductionRecord.DO_QUERY,doQuery);
			view.addEventListener(ProductionRecord.DO_ADD,doAddPrd);
			view.addEventListener(ProductionRecord.DO_UPDATE,doUpdatePrd);
			view.addEventListener(ProductionRecord.DO_DELETE,doDeletePrd);
			view.addEventListener(ProductionRecord.DO_REPORT,doReport);
			view.addEventListener(ProductionRecord.DO_LIST,doList);
		}
		private function get view():ProductionRecord{
			return viewComponent as ProductionRecord;
		}
		protected function doList(e:MouseEvent):void{
			view.currentState="basic";
		}
		protected function doReport(e:MouseEvent):void{
			view.currentState="report";
		}
		protected function doDeletePrd(e:ValueEvent):void{
			this.sendNotification(WellWindow.DO_DELETE_PRDRECORD,{id:e.vo.id});
		}
		protected function doUpdatePrd(e:ValueEvent):void{
			var window:UpdatePrdRecord=UpdatePrdRecord(MyAppFacade.openPopUpWindow(UpdatePrdRecord,UpdatePrdRecordMediator,UpdatePrdRecordMediator.NAME));
			window.prd=e.vo as WellPrdRecord;
			window.renderDay();
			
		}
		protected function doAddPrd(e:MouseEvent):void{
			var window:AddPrdRecord=AddPrdRecord(MyAppFacade.openPopUpWindow(AddPrdRecord,AddPrdRecordMediator,AddPrdRecordMediator.NAME));
			
		}
		protected function doQuery(e:MouseEvent):void{
			WellContext.queryDate=view.qDate.selectedDate;
			this.sendNotification(ProductionRecord.DO_REFRESH);
		}
		override public function listNotificationInterests():Array{
			return [WellProxy.PRD_RECORD_LOAD_OK];
		}
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case WellProxy.PRD_RECORD_LOAD_OK:
					var obj:Object=notification.getBody();
					view.dataList=obj as ArrayCollection;
					break;
			}
		}
	}
}